package com.cnhis.drgs.vo;


import com.github.pagehelper.PageInfo;

import java.io.Serializable;
import java.util.List;

public class Response implements Serializable {

    private static final int SUCCESS_CODE = 200;
    private static final int ERROR_CODE = -1;
    private static final String SUCCESS = "success";
    private static final String ERROR = "error";

    private int code;
    private int count;
    private String msg;
    private Object data;

    public static int getSuccessCode() {
        return SUCCESS_CODE;
    }

    public static int getErrorCode() {
        return ERROR_CODE;
    }

    public static String getSUCCESS() {
        return SUCCESS;
    }

    public static String getERROR() {
        return ERROR;
    }

    public int getCode() {
        return code;
    }

    public void setCode(int code) {
        this.code = code;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }

    public Response() {
    }

    public Response(int code) {
        this.code = code;
    }

    public Response(int code, int count) {
        this.code = code;
        this.count = count;
    }

    public Response(int code, int count, String msg) {
        this.code = code;
        this.count = count;
        this.msg = msg;
    }

    public Response(int code, int count, String msg, Object data) {
        this.code = code;
        this.count = count;
        this.msg = msg;
        this.data = data;
    }

    public static Response createSuccess() {
        return new Response(SUCCESS_CODE, 0, SUCCESS, null);
    }

    public static Response createSuccess(String msg) {
        return new Response(SUCCESS_CODE, 0, msg, null);
    }

    public static Response createSuccess(Object data) {
        return new Response(SUCCESS_CODE, 1, SUCCESS, data);
    }

    public static Response createSuccess(List<?> data) {
        return new Response(SUCCESS_CODE, data != null && data.size() > 0 ? data.size() : 0, SUCCESS, data);
    }

    public static Response createSuccess(PageInfo<?> pageInfo) {
        return new Response(SUCCESS_CODE, (int) (pageInfo != null && pageInfo.getTotal() > 0 ? pageInfo.getTotal() : 0), SUCCESS, pageInfo != null ? pageInfo.getList() : null);
    }

    public static Response createFail() {
        return new Response(ERROR_CODE, 0, ERROR, null);
    }

    //    public static Layui data() {
//        Layui layui = new Layui();
//        layui.put("code", SUCCESS_CODE);
//        layui.put("msg", "");
//        layui.put("count", 0);
//        layui.put("data", null);
//        return layui;
//    }
//
//    public static Layui data(String msg) {
//        Layui layui = new Layui();
//        layui.put("code", 0);
//        layui.put("msg", msg);
//        layui.put("count", 0);
//        layui.put("data", null);
//        return layui;
//    }
//
//
//    public static Layui data(List<?> data) {
//        Layui layui = new Layui();
//        layui.put("code", SUCCESS_CODE);
//        layui.put("msg", "");
//        layui.put("count", data != null && data.size() > 0 ? data.size() : 0);
//        layui.put("data", data);
//        return layui;
//    }
//
//
//    public static Layui data(PageInfo<?> pageInfo) {
//        Layui layui = new Layui();
//        layui.put("code", SUCCESS_CODE);
//        layui.put("msg", "");
//        layui.put("count", pageInfo != null && pageInfo.getTotal() > 0 ? pageInfo.getTotal() : 0);
//        layui.put("data", pageInfo != null ? pageInfo.getList() : null);
//        return layui;
//    }
}
